//package io.linfeng.common.config;
//
//import com.alibaba.nacos.api.annotation.NacosInjected;
//import com.alibaba.nacos.api.exception.NacosException;
//import com.alibaba.nacos.api.naming.NamingService;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.PostConstruct;
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.net.*;
//
//@Configuration
//public class NacosConfig {
//    @Value("${server.port}")
//    private int serverPort;
//    @Value("${spring.application.name}")
//    private String applicationName;
//    @Value("${other.ip}")
//    private String otherIp;
////    @NacosInjected
////    private NamingService namingService;
////    @PostConstruct
//
//    public void registerInstance() throws NacosException, IOException {
//        URL url = new URL(otherIp);
//        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//        connection.setRequestMethod("GET");
//        connection.connect();
//        String ipAddress = "";
//        int responseCode = connection.getResponseCode();
//        if (responseCode == HttpURLConnection.HTTP_OK) {
//            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//            ipAddress = reader.readLine();
//            reader.close();
//        }
//        connection.disconnect();
//        namingService.registerInstance(applicationName, ipAddress, serverPort);
//    }
//}
